How to get webform id in Drupal 8?

by audrey.hodkiewicz , in category: PHP , 2 years ago

How to get webform id in Drupal 8?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by dmitrypro77 , 2 years ago

@audrey.hodkiewicz You can get web form id from FormStateInterface as below in Drupal 8:


1
2
3
4
5
6
7
8
<?php

function your_module_form_alter(&$form, FormStateInterface &$form_state) {
  $web_form_id = $form_state->getFormObject()->getEntity()->getWebform()->id();
  if ($web_form_id === 'your_webform_id') {
    // ... your code is here
  }
}


by ava.bogan , a year ago

@audrey.hodkiewicz 

In Drupal 8, you can get the webform id by following these steps:

  1. Go to the webform list page (/admin/structure/webform).
  2. Find the webform you want to get the id for and click on the edit button (pencil icon).
  3. In the URL of the edit page, you will see the webform id at the end of the URL. It will be a number preceded by "webform" and a forward slash.


For example, if the URL is /node/1/edit/webform/2, the webform id is 2.